@file:Suppress("UNREACHABLE_CODE")

package com.lee.common.network

import com.google.gson.Gson
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import org.jetbrains.annotations.NotNull



/**
 * Created by gzh on 2019/4/30.
 * Author Liqiubo
 * desripbe return RequestBody
 */
fun getRequestBody(@NotNull hashMap: MutableMap<String, Any>): RequestBody {

    val data = StringBuffer()
    if (hashMap.isNotEmpty()) {
        val iterator = hashMap.entries.iterator()
        while (iterator.hasNext()) {
            val entry = iterator.next()
            data.append(entry.key).append("=").append(entry.value).append("&")
        }
    }

    data.append("clientType=1&")
    val json = data.substring(0, data.length - 1)

    return json.toRequestBody("application/x-www-form-urlencoded; charset=utf-8".toMediaTypeOrNull())

}